/**
 * @Creator: eyes
 * @Date: 2019/12/23
 */
import {TIME_DURATION} from '~/utils/const';

// 计算两个日期的天数差额
const getDaysDiff = dateRages => dateRages.length && dateRages[1].diff(dateRages[0], 'day');

// 根据日期区间动态获取时间粒度的可选值(比如:以10分钟为粒度)
export const getDurationOptions = dateRange => (
    getDaysDiff(dateRange) >= 1
        ? [
            {
                label: '按天查看',
                value: TIME_DURATION.ONE_DAY,
            },
        ]
        : [
            {
                label: '按10分钟查看',
                value: TIME_DURATION.MINUTES_10,
            },
        ]
);

export const getDefaultDuration = dateRange => (
    getDaysDiff(dateRange) >= 1
        ? TIME_DURATION.ONE_DAY
        : TIME_DURATION.MINUTES_10
);
